String.prototype.hashCode = function () {
  let hash = 0
  if (this.length === 0) {
    return hash
  }
  for (let i = 0; i < this.length; i++) {
    const charCode = this.charCodeAt(i) //获取指定位置的unicode编码
    console.log(hash);
    hash = ((hash << 5) - hash) + charCode
    hash &= hash
  }
  return hash
}
let str = 'acs'
console.log(str.hashCode());

function hashCode (string, limit = 7) {
  let PRIME = 31
  let hashCode = 0
  for (let item of string) {
    hashCode = PRIME * hashCode + item.charCodeAt()
  }
  return hashCode % limit
}
console.log(hashCode('acs'),'hashcode');